package Data;

public class Vector2D {
	
	public double x;
	public double y;

	public Vector2D(double x_, double y_) {
	    x = x_;
	    y = y_;
	}
	
	public Vector2D get() {
		return new Vector2D(x, y);
	}
	
	public Vector2D get(double _x, double _y) {
		return new Vector2D(x * _x, y * _y);
	}
	  
	public void add(Vector2D v) {
		y = y + v.y;
		x = x + v.x;
	}
	  
	public void sub(Vector2D v) {
		y = y - v.y;
		x = x - v.x;
	}
	  
	public void mult(double i) {
		y = y * i;
		x = x * i;
	}
	  
	public void multd(Vector2D v) {
		y = y * v.y;
		x = x * v.x;
	}
	  
	public void div(double m) {
		y = y / m;
		x = x / m;
	}
	  
	public void divd(Vector2D v) {
		y = y / v.y;
		x = x / v.x;
	}

	public double mag() {
		return Math.sqrt(x*x + y*y);
	}


	public void normalize() {
		double m = mag();
		if (m != 0) {
			div(m);
		}
	}

	public void limit(double max) {
		if (mag() > max) {
			normalize();
			mult(max);
		}
	}

	public void rotateRad(double d) {
		double bx = x;
		double by = y;
		x = bx * Math.cos(d) - by * Math.sin(d);
		y = bx * Math.sin(d) + by * Math.cos(d);
	}

	public void rotate(double d) {
		double buff = d * Math.PI/180.0;
		double bx = x;
		double by = y;
		x = bx * Math.cos(buff) - by * Math.sin(buff);
		y = bx * Math.sin(buff) + by * Math.cos(buff);
	}

}
